package com.admin.system.dao;

import com.admin.model.pojo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author caixiaofeng
 * @version 1.0
 * @Description: <<>>
 * @company 个人学习
 * @create 2021-03-05 20:04
 */
public interface CommonDao {

    @Select("SELECT * FROM sys_menu WHERE id IN (SELECT menu_id FROM sys_role_menu where role_id = #{roleId})")
    List<Menu> queryMenuByRoleId(@Param("roleId") String roleId);

    @Select("SELECT * FROM sys_menu WHERE PID=#{pid} ")
    List<Menu> findMenuByPId(@Param("pid") Long pid);

    @Select("SELECT * FROM sys_menu WHERE ID=#{id} ")
    Menu findMenuById(@Param("id") Long id);

    @Select("SELECT * FROM sys_dept WHERE ID=#{id} ")
    Role findDeptById(@Param("id") Long id);

    @Select("select * from sys_job where id in(select job_id from sys_user_job where user_id=#{userId})")
    List<Job> queryJobByUserId(@Param("userId") Long userId);

    @Select("SELECT * FROM sys_dept AS d LEFT JOIN sys_user_dept AS ud ON d.id = ud.dept_id where ud.user_id = #{userId}")
    List<Dept> queryDeptByUserId(@Param("userId") Long userId);

    @Select("select * from sys_role where id in(select role_id from sys_user_role where user_id=#{userId})")
    List<Role> queryRoleByUserId(@Param("userId") Long userId);

    @Select("select * from sys_user WHERE id in(select user_id from sys_user_role where role_id=#{roleId})")
    List<User> queryUserByRoleId(@Param("roleId") Long roleId);

    @Select("select * from sys_user WHERE id in(select user_id from sys_user_dept where dept_id=#{deptId})")
    List<User> queryUserByDeptId(Long deptId);
}
